package com.info33.platform.doc.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.info33.platform.common.mvc.controller.BaseController;
import com.info33.platform.common.mvc.vo.Result;
import com.info33.platform.doc.dto.DocFileSearchDTO;
import com.info33.platform.doc.dto.DocFileShareDTO;
import com.info33.platform.doc.entity.DocFileShare;
import com.info33.platform.doc.service.DocFileShareService;
import com.info33.platform.doc.vo.DocFileVO;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * @author admin
 */
@RestController
@RequestMapping("/DocFileShare")
@Api(tags = "文档管理 - 共享文件")
public class DocFileShareController extends BaseController<DocFileShareService, DocFileShare> {

    private final DocFileShareService docFileShareService;

    @Autowired
    public DocFileShareController(DocFileShareService docFileShareService) {
        super(docFileShareService);
        this.docFileShareService = docFileShareService;
    }
    
    @PostMapping("/shareFile")
    @ApiOperation(value = "共享文件")
    public Result<?> shareFile(@RequestBody DocFileShareDTO docFileShareDTO) {
        return docFileShareService.shareFile(docFileShareDTO);
    }
    
    @GetMapping("/calcelShare/{fileId}")
    @ApiOperation(value = "取消共享")
    public Result<?> calcelShare(@PathVariable Long fileId) {
        return docFileShareService.calcelShare(fileId);
    }
    
    @PostMapping(value = "/pageSharedFileList/{pageNum}/{pageSize}")
    @ApiOperation(value = "分页获取我共享的文档列表")
    public Result<IPage<DocFileVO>> pageSharedFileList(@RequestBody DocFileSearchDTO docFileSearchDTO, @PathVariable int pageNum, @PathVariable int pageSize) {
        IPage<DocFileVO> page = new Page<DocFileVO>(pageNum, pageSize);
        return Result.ok(docFileShareService.pageSharedFileList(page, docFileSearchDTO, getCurrentUser()));
    }
    
    @PostMapping(value = "/pageShareWithMeFile/{pageNum}/{pageSize}")
    @ApiOperation(value = "分页获取共享给我的文档列表")
    public Result<IPage<DocFileVO>> pageShareWithMeFile(@RequestBody DocFileSearchDTO docFileSearchDTO, @PathVariable int pageNum, @PathVariable int pageSize) {
        IPage<DocFileVO> page = new Page<DocFileVO>(pageNum, pageSize);
        return Result.ok(docFileShareService.pageShareWithMeFile(page, docFileSearchDTO, getCurrentUser()));
    }

}